<?php
	
### VPS DB Functions

### Defaults
$abspath=$_SERVER['DOCUMENT_ROOT'];

### supporting WP2.6 wp-load & custom wp-content / plugin dir
if ( file_exists( $abspath . '/wp-load.php') )
require_once( $abspath . '/wp-load.php' );
else
require_once( $abspath . '/wp-config.php' );

###get data from db based on array of form id
function get_vps_formdata( $strIds ) {
	### DB settings
	global $wpdb;
	$wpdb->cformssubmissions	= $wpdb->prefix . 'cformssubmissions';
	$wpdb->cformsdata       	= $wpdb->prefix . 'cformsdata';
	
	
### $strID is a list of form-ids to retrieve and returns an object containing all form data.
	
	
	$sql = "SELECT * FROM {$wpdb->cformsdata}";
	$ord = " ORDER BY f_id";
	
	### logic to add subid where clause if strID is not blank
	if ($strID != '') {
		$subid = " WHERE sub_id IN (".$strID.")";
		$sql = $sql.$subid.$ord;
	} else {
		$sql = $sql.$ord;
	}
	
	$result = $wpdb->get_results($sql);
	
	foreach ($result as $d){
		
		if( $offsets[$d->sub_id][$d->field_name]<>'')
	    	$offsets[$d->sub_id][$d->field_name]++;
        else
			$offsets[$d->sub_id][$d->field_name]=1;
		
        $tmp = '';
		if( $offsets[$d->sub_id][$d->field_name]>1)
        	$tmp = '-'.$offsets[$d->sub_id][$d->field_name];
	
        $vpsdata[$d->sub_id][$d->field_name.$tmp] = $d->field_val;
	}  
	return $vpsdata;
}
	
?>